package com.softer.wxzj.service.impl;

import com.softer.wxzj.common.entity.CommonResult;
import com.softer.wxzj.common.enums.NumberEnum;
import com.softer.wxzj.common.util.ShiroUserUtil;
import com.softer.wxzj.common.util.StringUtils;
import com.softer.wxzj.common.util.UUIDUtil;
import com.softer.wxzj.entity.AccRateCustomInfo;
import com.softer.wxzj.mapper.AccRateCustomInfoMapper;
import com.softer.wxzj.service.AccRateCustomInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashSet;
import java.util.List;

/**
 * @author zcz
 * @date 2019/7/29
 */
@Service
@Slf4j
public class AccRateCustomInfoServiceImpl implements AccRateCustomInfoService {

    @Autowired
    AccRateCustomInfoMapper accRateCustomInfoMapper;

    @Override
    public CommonResult insertOrUpdate(List<AccRateCustomInfo> accRateCustomInfoList) {
        int num = NumberEnum.ZERO.getNum();
        //判断承办银行是否重复
        HashSet<String> hashSet = new HashSet<>();
        for (AccRateCustomInfo a:accRateCustomInfoList) {
            hashSet.add(a.getBankId());
        }
        boolean isRepeat = accRateCustomInfoList.size() != hashSet.size();
        if(isRepeat){
            return CommonResult.strResult(NumberEnum.ZERO.getNum(),"承办银行不可重复！");
        }
        //执行操作
        for (AccRateCustomInfo accRateCustomInfo:accRateCustomInfoList) {
            if (StringUtils.isBlank(accRateCustomInfo.getId())){
                accRateCustomInfo.setId(UUIDUtil.getUUID());
                accRateCustomInfo.setCreater(ShiroUserUtil.getUserName());
            }
            num = accRateCustomInfoMapper.insertOrUpdate(accRateCustomInfo);
        }
        return CommonResult.ResponseResult(num);
    }

    @Override
    public CommonResult batchDelete(String ids) {
        int num = accRateCustomInfoMapper.batchDelete(ids);
        return CommonResult.ResponseResult(num);
    }

    @Override
    public List<AccRateCustomInfo> getList(AccRateCustomInfo accRateCustomInfo) {
        return accRateCustomInfoMapper.getList(accRateCustomInfo);
    }
}
